/**
 * 20080118 1547: Eric Kao was created.<br>
 */

package query.hql;

import java.util.Iterator;
import java.util.List;

import model.bean.PersonInfo;

import org.hibernate.Query;
import org.hibernate.Session;

import com.e885.hibernate.HibernateSessionFactory;
import com.e885.log.E885Logger;

/**
 * 測試基本的 HQL Query<br>
 * <br>
 * Copyright: Copyright (c) 2001-2008<br>
 * Company: E885 Group
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 */
public class HQLQuery
{
	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new HQLQuery();
	}

	@SuppressWarnings( "unchecked" )
	public HQLQuery()
	{
		Session session = HibernateSessionFactory.getSession();

		Query query = session.createQuery( "from PersonInfo" );

		List< PersonInfo > list = query.list();

		Iterator< PersonInfo > iterator = list.iterator();

		while( iterator.hasNext() )
		{
			PersonInfo bean = iterator.next();
			E885Logger.testLog.debug( "=========================" );
			E885Logger.testLog.debug( "id:" + bean.getId() );
			E885Logger.testLog.debug( "name:" + bean.getName() );
		}

		E885Logger.testLog.debug( "All row:" + list.size() );

		HibernateSessionFactory.closeSession();
	}

}
